import java.util.Scanner;
public class test529 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入年份：");
        int year = scanner.nextInt();
        System.out.print("请输入该年1月1日对应的星期数（0=周日, 1=周一, ..., 6=周六）：");
        int firstDayOfYear = scanner.nextInt();
        String[] months = {"January", "February", "March", "April", "May", "June",
                           "July", "August", "September", "October", "November", "December"};
        int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
            daysInMonth[1] = 29;
        }
        int currentDay = firstDayOfYear;
        for (int i = 0; i < 12; i++) {
            // 打印月份标题
            System.out.println("\n---------------------------");
            System.out.printf("          %s %d          %n", months[i], year);
            System.out.println("---------------------------");
            System.out.println("Sun Mon Tue Wed Thu Fri Sat");
            for (int j = 0; j < currentDay % 7; j++) {
                System.out.print("    ");
            }
            for (int day = 1; day <= daysInMonth[i]; day++) {
                System.out.printf("%3d ", day);
                if ((currentDay + day) % 7 == 0) {
                    System.out.println();
                }
            }
            currentDay += daysInMonth[i];
            System.out.println(); 
        }scanner.close();
    }
}
